<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link href="css/bootstrap.css" rel="stylesheet">
    <script src="js/jquery-1.9.1.min.js"></script>
    <script src="js/tether.min.js"></script>
    <script src="js/bootstrap.js"></script>
    <style>
        #myAlert {
            position: fixed;
            bottom: 0px;
            left: 0;
            right: 0;
            text-align: center;
        }
    </style>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>

<body>
<div class="col-sm-5">
    <div class="reg_submit" style="padding: 100px 100px 10px;">
        <form class="bs-example bs-example-form" role="form">
            <div class="input-group">
                <span class="input-group-addon">Account </span>
                <input type="text" class="form-username" placeholder="your account">
            </div>
            <br>
            <div class="input-group">
                <span class="input-group-addon">Password</span>
                <input type="password" class="form-password" placeholder="your password">
            </div>
            <br>
            <button id="reg-button" type="button" data-loading-text="Loading...." class="btn btn-primary"
                    autocomplete="off" data-toggle="buttons">Submit
            </button>
        </form>
    </div>
</div>
<div id="erro_div">
</div>
<script>
    $(function () {
        $("#reg-button").on("click", function () {
            var that = $(this);
//            that.text(that.attr("data-loading-text"))
            var username = $(".form-username").val();
            var password = $(".form-password").val();
            var formdata = {
                "userName": username,
                "password": password
            };
            $.ajax({
                type: "POST",
                url: "/api/v1/account/login.sena",
                contentType: "application/json; charset=utf-8",
                data: JSON.stringify(formdata),
                dataType: "json",
                success: function (date) {
                    if (date.code != 0) {
                        showMsg('Erro!', date.message, 'alert-danger');
                    } else {
                        var obj = date.data;
                        showMsg('Suuccess!', ',Id=' + obj.id, 'alert-success');
                    }
                },
                error: function (message) {
                    showMsg('Warning!', 'Network connection exception', 'alert-warning');
                }
            });
        })

        var showMsg = function (title, msg, status) {
            $("#myAlert").css('display', 'block');
            $("#erro_div").empty();
            $("#erro_div").append('<div id="myAlert" class="alert ' + status + '">' +
                '<a href="#" class="close" data-dismiss="alert">&times;</a>' +
                '<strong>' + title + '</strong>' + msg);
        }
    })
</script>

</body>
</html>